package br.indt.framework.ui.common;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import br.indt.framework.ui.ImageLoader;

public abstract class TitleBar extends Widget 
{
	protected static final String TOPBAR_DEFAULT_LEFT_SLICE = "/topbar_default_left_slice.png";
	protected static final String TOPBAR_DEFAULT_MIDDLE_SLICE = "/topbar_default_midle_slice.png";
	protected static final String TOPBAR_DEFAULT_RIGHT_SLICE = "/topbar_default_right_slice.png";
	
	protected Label titleLabel = null;
	protected int titleLabelLeft = 0;
	protected Image leftSideImage = null;
	protected Image middleSlice = null;
	protected Image rightSideImage = null;

	public TitleBar(String name, String title) 
	{
		super(name);
		
		try 
		{
			//setBackgroundColor(0xFF7F00);
			setBackgroundImages(ImageLoader.load(TOPBAR_DEFAULT_LEFT_SLICE), ImageLoader.load(TOPBAR_DEFAULT_MIDDLE_SLICE), ImageLoader.load(TOPBAR_DEFAULT_RIGHT_SLICE));
			setHeight(Display.TITLE_BAR_HEIGHT);
			setWidth(Display.getInstance().getWidth());
		
			titleLabel = new Label("titleLabel", title, false, 1, null);
			titleLabel.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
			titleLabel.setMargin(0, ((Display.TITLE_BAR_HEIGHT - titleLabel.getFont().getHeight()) / 2), 4, 0);			
		}
		catch (Exception e) 
		{
			System.out.println("TitleBar::constructor - e = " + e);
		}
	}

	public void setTitle(String title)
	{
		titleLabel.setText(title);
	}

	public void setTitleTextColor(int color)
	{
		titleLabel.setTextColor(color);
	}
	
	public void setTitleAlignment(String title)
	{
		titleLabel.setText(title);
	}

	protected void paint(Graphics g, int x, int y, int maxWidth, int maxHeight)
	{	
		super.paint(g, x, y, maxWidth, maxHeight);
		
		try 
		{			
			titleLabel.paint(g, titleLabelLeft, y, maxWidth, maxHeight);
		}
		catch (Exception e) {
			//empty
		}
	}
}